// eee.Sheffield.PZ.Imaging
//
// Copyright ?Ping Zou, 2006
// sg71.cherub@gmail.com

using eee.Sheffield.PZ.Math;
using System.Drawing;
using System.Drawing.Imaging;
using System;
using System.Collections.Generic;
using System.Text;

namespace eee.Sheffield.PZ.Imaging.ImageFilter
{
    public class SobelY : DoubleKernel2D // ImageFilter//, IGraylevelImageFilter
    {
        #region Fields
        //private static double[,] _kernelY = new double[,]
        //{
        //    {-1,  0,  1},
        //    {-2,  0,  2},
        //    {-1,  0,  1}
        //};

        //private string _flag = "[Image -> Gradient -> SobelY]";
        #endregion

        //#region Properties
        //public string Log() { return _log; }
        //public string Flag() { return _flag; }
        //#endregion

        #region Constructor
        public SobelY()
        {
            _flag = "[Image -> Gradient -> SobelY]";
            _normalize = true;
            _kernel = new double[,]
		    {
                {-1,  0,  1},
			    {-2,  0,  2},
			    {-1,  0,  1}
		    };
        }
        #endregion

        #region Apply filter
        //public Bitmap ApplyGraylevelImageFilter(Bitmap srcImage) { return Apply(srcImage, out _log); }
        //public PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix) { return ApplyDouble(srcMatrix, out _log); }

        //private Bitmap Apply(Bitmap srcImage, out string logText)
        //{
        //    PZMath_matrix srcMatrix = _converter.ConvertGraylevelBitmapToMatrix(srcImage);
        //    PZMath_matrix dstMatrix = ApplyDouble(srcMatrix, out logText);
        //    Bitmap dstImage = _converter.ConvertMatrixToGraylevelBitmap(dstMatrix, true);
        //    return dstImage;
        //}     

        //protected override PZMath_matrix ApplyDoubleGraylevelImageFilter(PZMath_matrix srcMatrix, out string logText)
        //{
        //    #region source and dst matrix
        //    // get source
        //    int width = srcMatrix.ColumnCount;
        //    int height = srcMatrix.RowCount;

        //    // create dstMatrix
        //    PZMath_matrix dstMatrix = new PZMath_matrix(height, width);
        //    int heightM1 = height - 1;
        //    int widthM1 = width - 1;
        //    int heightM2 = height - 2;
        //    int widthM2 = width - 2;
        //    #endregion

        //    #region apply filter, X direction
        //    // for each pixel
        //    for (int y = 1; y < heightM1; y++)
        //    {
        //        for (int x = 1; x < widthM1; x++)
        //        {
        //            double gy = 0;
        //            // for each kernel row
        //            for (int i = 0; i < 3; i++)
        //            {
        //                // for each kernel column
        //                for (int j = 0; j < 3; j++)
        //                {
        //                    // source value
        //                    double v = srcMatrix[y + i - 1, x + j - 1];
        //                    gy += v * _kernelY[i, j];
        //                }
        //            }
        //            dstMatrix[y, x] = gy;
        //        }
        //    }
        //    #endregion

        //    #region copy "margin"
        //    // for each row
        //    for (int y = 0; y < height; y++)
        //    {
        //        dstMatrix[y, 0] = dstMatrix[y, 1];
        //        dstMatrix[y, widthM1] = dstMatrix[y, widthM2];
        //    }
        //    // for each column
        //    for (int x = 0; x < width; x++)
        //    {
        //        dstMatrix[0, x] = dstMatrix[1, x];
        //        dstMatrix[heightM1, x] = dstMatrix[heightM2, x];
        //    }
        //    #endregion

        //    //PZMath_matrix dstMatrix = srcMatrix.Convolute(new PZMath_matrix(_kernelY));
        //    logText = "succeeds.";
        //    return dstMatrix;
        //} // ApplyDoubleGraylevelImageFilter()

        //protected override PZMath_matrix[] ApplyDoubleColourImageFilter(PZMath_matrix[] srcMatrixArray, out string logText)
        //{
        //    PZMath_matrix[] dstMatrixArray = new PZMath_matrix[3];
        //    for (int i = 0; i < 3; i++)
        //        dstMatrixArray[i] = srcMatrixArray[i].Convolute(new PZMath_matrix(_kernelY));
        //    logText = "succeeds";
        //    return dstMatrixArray;
        //} // ApplyDoubleColourImageFilter()
        #endregion

    }
}
